package net.zigin.nhi.could.waste.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.zigin.nhi.could.waste.annotation.EpiResponseFilter;
import net.zigin.nhi.could.waste.annotation.EpiResponseFilters;
import net.zigin.nhi.could.waste.dto.SysDictionDto;
import net.zigin.nhi.could.waste.service.SysDictionService;

import net.zigin.nhi.could.waste.vo.JsonForResult;
import net.zigin.nhi.could.waste.vo.SysDictionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * SysDiction控制器类
 * @ClassName: SysDictionController
 * @author mgw1986
 * @date 2021-9-20 22:06:06
 * @version V1.0
 */
@Api(tags = "字典管理")
@RestController
@RequestMapping("/sysDiction")
public class SysDictionController extends BaseController {
	@Autowired
	private SysDictionService sysDictionService;

	@GetMapping("/getListByType")
	@ApiOperation("员工详情")
	@ApiImplicitParam(name = "type", value = "字典类型", required = true, dataType = "String")
	@EpiResponseFilters({
			@EpiResponseFilter(exclude = "icon,id")
	})
	public JsonForResult<List<SysDictionVo>> getListByType(String type){
		List<SysDictionVo> list = sysDictionService.getListByType(type);
		return JsonForResult.<List<SysDictionVo>>builder().data(list).success(true).build();
	}

	/**
	 * 新增编辑字典
	 *
	 * @param sysDictionDto 字典信息
	 * @return 字典ID
	 */
	@ApiOperation("新增编辑字典")
	@ApiImplicitParam(name = "sysDictionDto", value = "字典信息", required = true, dataType = "SysDictionDto")
	@PostMapping("/save")
	public JsonForResult<String> sava(@RequestBody SysDictionDto sysDictionDto) {
		String id = sysDictionService.saveOrUpdate(sysDictionDto);
		return JsonForResult.<String>builder().data(id).success(true).build();
	}

	/**
	 * 字典列表
	 *
	 * @param sysDictionDto 字典信息
	 * @return 字典列表
	 */
	@ApiOperation("字典列表")
	@ApiImplicitParam(name = "sysDictionDto", value = "字典信息", required = true, dataType = "SysDictionDto")
	@PostMapping("/getList")
	public JsonForResult<List<SysDictionVo>> getList(@RequestBody SysDictionDto sysDictionDto) {
		List<SysDictionVo> list = sysDictionService.getList(sysDictionDto);
		Integer count = sysDictionService.getCount(sysDictionDto);
		return JsonForResult.<List<SysDictionVo>>builder()
				.data(list).total(count)
				.success(true).build();
	}

	/**
	 * 删除字典
	 *
	 * @param id ID
	 * @return
	 */
	@DeleteMapping("/remove/{id}")
	@ApiOperation("删除字典")
	@ApiImplicitParam(name = "id", value = "字典id", required = true, dataType = "String")
	public JsonForResult remove(@PathVariable String id) {
		sysDictionService.deleteByPrimaryKey(id);
		return JsonForResult.builder().success(true).build();
	}

}
